<?php

use Drupal\mxm_article_tags\Entity\MxmArticleTags;
use Drupal\mxm_article_tags\Entity\MxmArticleTagsBind;

function mxm_article_tags_mxm_article_tags_entity_form($form, &$form_state, MxmArticleTags $e, $op) {
  $form_state['build_info']['files']['form'] = drupal_get_path('module', 'mxm_article_tags') . '/mxm_article_tags.forms.inc';
  $form_state[MxmArticleTags::class] = $e;

  $form['title'] = [
    '#type' => 'textfield',
    '#title' => t('标题'),
    '#default_value' => $e->title,
    '#required' => TRUE,
  ];
  $form['sort'] = [
    '#type' => 'textfield',
    '#title' => t('排序'),
    '#default_value' => $e->sort,
    '#required' => TRUE,
    '#element_validate' => ['element_validate_integer'],
  ];
  $form['status'] = [
    '#type' => 'checkbox',
    '#title' => t('启用'),
    '#default_value' => $e->status,
  ];

  field_attach_form($e->entityType(), $e, $form, $form_state);

  $form['actions'] = ['#type' => 'actions'];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => t('保存'),
  ];
  return $form;
}

function mxm_article_tags_mxm_article_tags_entity_form_submit($form, &$form_state) {
  $e = $form_state[MxmArticleTags::class];
  if ($e instanceof MxmArticleTags) {
    entity_form_submit_build_entity($e->entityType(), $e, $form, $form_state);
    $e->save();
  }
}

function mxm_article_tags_mxm_article_tags_delete_form($form, &$form_state, MxmArticleTags $e) {
  $form_state['build_info']['files']['form'] = drupal_get_path('module', 'mxm_article_tags') . '/mxm_article_tags.forms.inc';
  $form_state[MxmArticleTags::class] = $e;
  return confirm_form($form,
    t('Are you sure you want to delete %title?', ['%title' => $e->label()]),
    'admin/content/mxm_article_tags/' . $e->id,
    t('This action cannot be undone.'),
    t('Delete'),
    t('Cancel')
  );
}

function mxm_article_tags_mxm_article_tags_delete_form_submit($form, &$form_state) {
  $e = $form_state[MxmArticleTags::class];
  if ($e instanceof MxmArticleTags) {
    $e->delete();
  }
  $form_state['redirect'] = 'admin/content/mxm_article_tags';
}

function mxm_article_tags_mxm_article_tags_bind_entity_form($form, &$form_state, MxmArticleTagsBind $e, $op) {
  $form_state['build_info']['files']['form'] = drupal_get_path('module', 'mxm_article_tags') . '/mxm_article_tags.forms.inc';
  $form_state[MxmArticleTagsBind::class] = $e;

  field_attach_form($e->entityType(), $e, $form, $form_state);

  $form['actions'] = ['#type' => 'actions'];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => t('保存'),
  ];
  return $form;
}

function mxm_article_tags_mxm_article_tags_bind_entity_form_submit($form, &$form_state) {
  $e = $form_state[MxmArticleTagsBind::class];
  if ($e instanceof MxmArticleTagsBind) {
    entity_form_submit_build_entity($e->entityType(), $e, $form, $form_state);
    $e->save();
  }
}

function mxm_article_tags_mxm_article_tags_bind_delete_form($form, &$form_state, MxmArticleTagsBind $e) {
  $form_state['build_info']['files']['form'] = drupal_get_path('module', 'mxm_article_tags') . '/mxm_article_tags.forms.inc';
  $form_state[MxmArticleTagsBind::class] = $e;
  return confirm_form($form,
    t('Are you sure you want to delete %title?', ['%title' => $e->label()]),
    'admin/content/mxm_article_tags_bind/' . $e->id,
    t('This action cannot be undone.'),
    t('Delete'),
    t('Cancel')
  );
}

function mxm_article_tags_mxm_article_tags_bind_delete_form_submit($form, &$form_state) {
  $e = $form_state[MxmArticleTagsBind::class];
  if ($e instanceof MxmArticleTagsBind) {
    $e->delete();
  }
  $form_state['redirect'] = 'admin/content/mxm_article_tags_bind';
}

